package cre.sample.test.ds.order;

/**
 * Created by CreGu on 2016/5/25.
 */
public class ArrayShell extends ArrayAbstract{

    public ArrayShell(int size) {
        super(size);
    }

    public void shellSort() {
//        初始标记为h
        int h = 1;
        while (h < elements/3) {
            h = 3 * h + 1;
        }
        while (h >= 1) {
            for (int out = h; out < elements; out++) {
                long tmp = arr[out];//选中的元素放临时变量
                int in = out;

                while (in > h - 1 && arr[in - h] > tmp) {
                    arr[in] = arr[in - h];
                    in-=h;
                }
                arr[in] = tmp;
            }
            h = (h - 1) / 3;
        }
    }
}
